package com.yujn.controller;

import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.databind.util.JSONPObject;
import com.yujn.bean.Order;
import com.yujn.bean.Order2;
import com.yujn.bean.dto.OrderDTO;
import com.yujn.bean.struct.OrderStruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@RequestMapping("/order")
@RestController
public class OrderController {

    @Autowired
    private Order order;

    @Autowired
    private Order2 order2;

    @Autowired
    private Environment environment;

    @Value("${order.number}")
    private String orderNumber;

    @Value("${order.price}")
    private String price;

    @GetMapping("/getOrderNumber")
    public String getOrderNumber(){
        return orderNumber + price;
    }

    @GetMapping("/getOrderPrice")
    public BigDecimal getOrderPrice(){
        return environment.getProperty("order.price",BigDecimal.class);
    }


    @GetMapping("/getOrder")
    public String getOrder(){
        return JSONUtil.toJsonStr(order);
    }

    @GetMapping("/getOrder2")
    public String getOrder2(){
        return JSONUtil.toJsonStr(order2);
    }

    @GetMapping("/getOrderDTO")
    public String getOrderDTO(){
        OrderDTO orderDTO = OrderStruct.INSTE.toDTO(order);
        orderDTO.setLogistic("SF");
        return JSONUtil.toJsonStr(orderDTO);
    }

}
